home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / bin / metasend < prev    next >
Encoding:
Text File  |  1995-07-03  |  5.3 KB  |  240 lines

  1. :
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  15. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  16. # Permission to use, copy, modify, and distribute this material
  17. # for any purpose and without fee is hereby granted, provided
  18. # that the above copyright notice and this permission notice
  19. # appear in all copies, and that the name of Z-Code Software not
  20. # be used in advertising or publicity pertaining to this
  21. # material without the specific, prior written permission
  22. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  23. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  24. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  25. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  26.  
  27. if [ -z "$METAMAIL_TMPDIR" ]
  28. then METAMAIL_TMPDIR=/tmp
  29. fi
  30.  
  31. MustDelete=0
  32. batchmode=0
  33. splitsize=100000
  34.  
  35. while test ! -z "$*"
  36. do
  37.     case $1 in
  38.         -S) shift
  39.             if test -z "$*"
  40.             then
  41.             echo "-S requires a following argument, the SPLIT threshhold"
  42.             exit 1
  43.             fi
  44.             splitsize=$1
  45.             shift ;;
  46.  
  47.         -b) batchmode=1
  48.             shift ;;
  49.  
  50.         -c) shift
  51.             if test -z "$*"
  52.             then
  53.                 echo "-c requires a following argument, the CC address"
  54.             exit 1
  55.             fi
  56.             cc=$1
  57.             shift ;;
  58.  
  59.         -s) shift
  60.             if test -z "$*"
  61.             then
  62.             echo "-s requires a following argument, the SUBJECT"
  63.             exit 1
  64.             fi
  65.             subject=$1
  66.             shift ;;
  67.  
  68.         -t) shift
  69.             if test -z "$*"
  70.             then
  71.             echo "-t requires a following argument, the TO address"
  72.             exit 1
  73.             fi
  74.             to=$1
  75.             shift ;;
  76.  
  77.         -e) shift
  78.             if test -z "$*"
  79.             then
  80.             echo "-e requires a following argument, the ENCODING value"
  81.             exit 1
  82.             fi
  83.             encode=$1
  84.             shift ;;
  85.  
  86.         -f) shift
  87.             if test -z "$*"
  88.             then
  89.             echo "-f requires a following argument, the DATA FILE"
  90.             exit 1
  91.             fi
  92.             datafile=$1
  93.             shift ;;
  94.  
  95.         -m) shift
  96.             if test -z "$*"
  97.             then
  98.             echo "-m requires a following argument, the MIME CONTENT-TYPE"
  99.             exit 1
  100.             fi
  101.             ctype=$1
  102.             shift ;;
  103.  
  104.         -z) MustDelete=1
  105.             shift ;;
  106.  
  107.         *) echo UNRECOGNIZED METASEND OPTION: $1
  108.            exit 1 ;;
  109.     esac
  110. done
  111.  
  112. if test $batchmode -eq 0
  113. then
  114.     if test -z "${to:-}"
  115.     then
  116.         echo-n "To: "
  117.         read to
  118.     fi
  119.     if test -z "${subject:-}"
  120.     then
  121.             echo-n "Subject: "
  122.         read subject
  123.     fi
  124.     if test -z "${cc:-}"
  125.     then
  126.         echo-n "CC: "
  127.         read cc
  128.     fi
  129.     if test -z "${ctype:-}"
  130.     then
  131.             echo-n "Content-type: "
  132.         read ctype
  133.     fi
  134.     if test -z "${datafile:-}"
  135.     then
  136.         looping=1
  137.         while test $looping -eq 1
  138.         do
  139.             echo-n "Name of file containing $ctype data: "
  140.             read datafile
  141.             if test -r "$datafile"
  142.             then
  143.                 looping=0
  144.             else
  145.                 echo "The file $datafile does not exist."
  146.             fi
  147.         done
  148.     fi
  149.  
  150.     if test -z "${encode:-}"
  151.     then
  152.         looping=1
  153.         while test $looping -eq 1
  154.         do
  155.             echo "Do you want to encode this data for sending through the mail?"
  156.             echo "  1 -- No, it is already in 7 bit ASCII"
  157.             echo "  2 -- Yes, encode in base64 (most efficient)"
  158.             echo "  3 -- Yes, encode in quoted-printable (less efficient, more readable)"
  159.             echo "  4 -- Yes, encode it using uuencode (not standard, being phased out)"
  160.             read encode
  161.             looping=0
  162.             case "$encode" in
  163.                 1) encodingprog=cat
  164.                    encode=7bit ;;
  165.                 2) encodingprog="mimencode -b"
  166.                    encode=base64 ;;
  167.                 3) encodingprog="mimencode -q"
  168.                    encode=quoted-printable ;;
  169.                 4) encodingprog="uuencode $datafile"
  170.                    encode=x-uue ;;
  171.                 *) echo Unrecognized answer, please try again.
  172.                    looping=1 ;;
  173.             esac
  174.         done
  175.     fi
  176. else
  177.     if test -z "${to:-}" \
  178.         -o -z "${subject:-}" \
  179.         -o -z "${ctype:-}" \
  180.         -o -z "${datafile:-}"
  181.     then
  182.         echo "metasend: in batch mode, -t, -s, -f, and -m are all required"
  183.         exit 1
  184.     fi
  185.  
  186.     if test ! -r "$datafile"
  187.     then
  188.         echo "metasend: The file $datafile does not exist"
  189.         exit 1
  190.     fi
  191.  
  192.     if test -z "${cc:-}"
  193.     then
  194.         cc=''
  195.     fi
  196.  
  197.     if test -z "${encode:-}"
  198.     then
  199.         case "$ctype" in
  200.             text*) encodingprog="mimencode -q"
  201.                    encode=quoted-printable ;;
  202.             *) encodingprog="mimencode -b"
  203.                encode=base64 ;;
  204.         esac
  205.     else
  206.         case "$encode" in
  207.             base64) encodingprog="mimencode -b" ;;
  208.             x-uue) encodingprog="uuencode $datafile" ;;
  209.             *) encodingprog="mimencode -q"
  210.                encode=quoted-printable ;;
  211.         esac
  212.     fi
  213. fi
  214.  
  215. fname=$METAMAIL_TMPDIR/metasend.$$
  216. echo "To: $to" > $fname
  217. echo "Subject: $subject" >> $fname
  218. echo "CC: $cc" >> $fname
  219. echo "MIME-Version: 1.0" >> $fname
  220. echo "Content-type: $ctype" >> $fname
  221. echo "Content-Transfer-Encoding: $encode" >> $fname
  222. echo "" >> $fname
  223. "$encodingprog" < "$datafile" >> "$fname"
  224. # Ensure last line has trailing carriage return
  225. echo "" >> "$fname"
  226.  
  227. splitmail -s $splitsize -d $fname
  228.  
  229. if test $? -eq 0
  230. then
  231.     rm -f $fname
  232. elif test "$MustDelete" -eq 1
  233. then
  234.     echo Mail delivery failed
  235.     rm -f $fname
  236. else
  237.     echo "Mail delivery failed, draft mail is in $fname"
  238. fi
  239.